<template>
  <div class="page-container">
    <div class="header">
      <img class="avatar" :src="user.avatar" alt="" />
      <h3>{{ user.username }}</h3>
    </div>
    <van-grid :column-num="3">
      <van-grid-item icon="clock-o" text="历史记录" />
      <van-grid-item icon="bookmark-o" text="我的收藏" />
      <van-grid-item icon="good-job-o" text="我的点赞" />
    </van-grid>

    <van-cell-group>
      <van-cell title="推荐分享" is-link />
      <van-cell title="意见反馈" is-link />
      <van-cell title="关于我们" is-link />
      <van-cell title="退出登录" is-link @click="loginout" />
    </van-cell-group>
  </div>
</template>

<script>
import { deleteToken } from "../utils/token";
import { getUserInfo } from "../api/user";
export default {
  data() {
    return {
      user: {
        avatar: "",
        username: "",
      },
    };
  },
  created() {
    this.userInfo();
  },
  methods: {
    async userInfo() {
      const res = await getUserInfo();
      this.user = res.data.data;
    },
    loginout() {
      deleteToken();
      this.$router.push("/login");
      this.$toast.success("退出成功");
    },
  },
};
</script>

<style lang="less" scoped>
.page-container {
  height: calc(100vh - 50px);
  background-color: #f4f4f4;
  padding: 0 10px;
}
.header {
  display: flex;
  align-items: center;
  height: 120px;
}
.avatar {
  width: 50px;
  height: 50px;
  border-radius: 50%;
  margin-right: 16px;
}
.van-grid {
  margin-bottom: 20px;
}
</style>
